import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit

def func(x, a):
    return a*x

x = np.linspace(0,4,50)

x = np.array([0,1,2,3,4,5])
y = np.array([i*2 for i in x])
yn = np.array([0, 1.2,2.1,2.9,4.3,6])

popt, pcov = curve_fit(func, x, yn)

plt.figure()
plt.plot(x, yn, 'ko', label="Original Noised Data")
plt.plot(x, func(x, *popt), 'r-', label="Fitted Curve")
plt.legend()
plt.show()
